<?php
	DEFINE('H1', 'MySQLI Test 6');
	DEFINE('TITLE','MySQLI Test 6');
	require('includes/header.php');
	require_once('db/DBparms.php');
?>	
	<h2><?PHP echo H1 ?></h2>

<?php

	$mysqli = new mysqli(DBHOST, DBUSER, DBPWD, "appl");
	
		$result = $mysqli->query("Select id, username, security_token from users");
		
		echo "Returned " . $result->num_rows . " rows.<br />";
		$row = $result->fetch_array();
		echo "Array access: 0 is $row[0]; 1 is $row[1]; 2 is $row[2] <br />";
		echo "Array access: 'id' is " . $row['id'] . "; 'username' is " . $row['username'] . "; 'security_token' is " . $row['security_token']." <br />";
		echo "<br /><br />";
		
		$row = $result->fetch_object();
		echo "Object access: '->id' is " . $row->id . "; '->username' is " . $row->username . "; '->security_token' is " .  $row->security_token ."<br />";
		
		$result->close();
		
		echo "<br /><br />";
		
		
		$ins = "insert into users (username, password, security_token) Values " . "('Bob Harris', '" . sha1('LOT') . "',8)";
		$result = $mysqli->query($ins);
		$newID = $mysqli->insert_id;
		echo "INSERTED A NEW RECORD AT $newID <br />";
		
		echo "<br /><br />";
				
		$updt = "update users set security_token=154 where username = 'Bob Harris'";
		$result = $mysqli->query($updt);
		echo "UPDATED A RECORD AT $newID <br />";
		echo "Count of affected rows: " . $mysqli->affected_rows . "<br />";
		
		$del = "delete from users where username = 'Bob Harris'";
		$result = $mysqli->query($del);
		echo "DELETED A RECORD AT $newID <br />";
		echo "Count of affected rows: " . $mysqli->affected_rows . "<br />";
		
		
	$mysqli->close();

?>

<?php
	require('includes/footer.php');
?>